package com.chenglu.android.common.base;


import android.util.Log;

import org.json.JSONObject;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @author lyj
 * @Created by Copyright © 2023 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * Description：BasePresenter
 */
public class BasePresenter<V extends BaseView> {

    protected V mView;


    /**
     * 绑定view，一般在初始化中调用该方法
     *
     * @param view view
     */
    public void attachView(V view) {
        this.mView = view;
    }

    /**
     * 解除绑定view，一般在onDestroy中调用
     */

    public void detachView() {
        this.mView = null;
    }

    /**
     * View是否绑定
     *
     * @return
     */
    public boolean isViewAttached() {
        return mView != null;
    }


    /**
     * 显示加载框
     */
    protected void showLoading() {
        mView.showLoading();
    }

    /**
     * 隐藏加载框
     */
    protected void dismissLoading() {
        mView.dismissLoading();
    }


    public RequestBody getRequestBody(JSONObject jsonObject) {

        Log.d("qqqqqq", jsonObject.toString().replace("\\",""));
        return RequestBody.create(
                MediaType.parse("application/json; charset=utf-8"),
                jsonObject.toString().replace("\\","")
        );
    }
}
